<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>

<script type="text/javascript">
	 
	  $(function(){
	    $("#getCode").removeAttr("disabled");//记得括号里，对应的是id
	    //发送验证码
	    $("#getCode").click(function(){
	    
	        $.ajax({
	        url:"servlet/MessageServlet",//ajax提交表单
	        data:{
	          "phone":$("#phone").val()
	        },
	        type:"post",
	        async:true,
	        dataType:"text",
	        success:function(data){
	           if(data=='true'){
	             alert("验证码已发送");
	             time(this);
	           }else
	              alert("发送失败");
	        },
	        error:function(){
	            alert("error");
	       }
	    });
	    });
	  
	  //验证
	    $("#validate").click(function(){
	     var code=$("#code");
	     if(code.val()==''){
	         alert("验证码不能为空");
	         return;
	     }
	       $.ajax({
	       url:"servlet/CodeServlet",
	       data:{
	        "code":$("#code").val()
	       },
	       type:"post",
	       async:true,
	       dataTyape:"text",
	       success:function(data){
	          if(data=='true'){
	            alert("成功!");
	            window.location.href="./index.jsp";
	           }
	            else{
	               alert("验证码错误");
	               window.location.href="./index.jsp";
	            }
	       },
	       error:function(){
	            alert("发送失败请重新发送");
	            window.location.href="./MyJsp.jsp";
	       }
	    
	  });
	  });
	  });
	  //倒计时
	   var wait=60;
	  function time(obj){
	    if(wait==0){
	      $("#getCode").removeAttr("disabled");
	      $("#getCode").val("重新获取");
	      wait=60;
	    }else{
	        $("#getCode").attr("disabled","true");
	        $("#getCode").val(wait+"s");
	        wait--;
	        setTimeout(function(){//倒计时的方法
	            time(obj);
	        },1000);        //1s
	  }
	    }
	    
	</script> 


<body>
	<form id="send" class="leavespace" action="">  
         <input id="phone" name="username" class="username" 
          tabindex="1" placeholder="手机号/如果手机号换了那就gg" accesskey="n" type="text" autocomplete ="off">
         <p class=""></p>
       <br>     
         <input id="password" name="password" class="password"  
          tabindex="2" placeholder="新的密码" accesskey="p" type="password" autocomplete ="off">
           <div class="">
       </div>
        <br>
        <input id="code" type="text" placeholder="验证码输入" class="code" tabindex="3"> 
       <input id="getCode" name="getCode" class="codeButton" type="button" value="发送"  autocomplete ="off"/>
       <br><br><br>
       <input type="button" class="button buttons" id="validate" value="确认" >
       </form> 
</body>
